package com.abc.model;

import java.util.Arrays;

/**
 * Contains monthly efforts for developer's year.
 */
public class PersonYearEffort {
	
	private String year;
	
	private String developer;
	
	public PersonYearEffort(String developerName, String theYear) {
		this.developer = developerName;
		this.year = theYear;
	}

	private double[] efforts = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
	
	public void setEffort(int month, int effort) {
		efforts[month - 1] = effort;
	}
	
	public double addEffort(int month, double effort) {
		efforts[month - 1] += effort;
		return efforts[month-1];
	}
	
	public double getEffort(int month) {
		return efforts[month - 1];
	}

	public String getYear() {
		return year;
	}

	public String getDeveloper() {
		return developer;
	}
	
	public String getId() {
		return getDeveloper() + "-" + getYear();
	}
	
	@Override
	public String toString() {
		return this.developer + " " + pretty(efforts);
	}
	
	private String pretty(double[] values) {
		StringBuffer sb = new StringBuffer();
		for(double val : values) {
			sb.append(" " + val);
		}
		return sb.toString();
	}

	public double getAllEffortForYear(){
		double all = 0;
		for(double a: this.efforts){
			all=all+a;
		}
		return all;
	}
}
